package com.xunfang.dao;

import com.xunfang.bean.Student;
import com.xunfang.utils.PagingQueryBean;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;
import java.util.List;

import static com.xunfang.utils.MyUtils.QUERY_RUNNER;

/**
 * @Author lss
 * @CreateTime 2024/6/11
 * @Description
 */
public class StudentDao {


    public int queryTotalSize() {
        String sql = "select count(*) from student";
        try {
            long l = (long)QUERY_RUNNER.query(sql,new ScalarHandler());
            return (int)l;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }

    public List<Student> pageQuery(PagingQueryBean pagingQueryBean) {
        String sql = "select * from student limit ?,?";
        try {
            return QUERY_RUNNER.query(sql,new BeanListHandler<>(Student.class),
                    pagingQueryBean.getIndex(),
                    pagingQueryBean.getPageSize());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
